package com.lisp.springframework.core.annotation;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

@Configuration
@PropertySource(value="classpath:/app.properties")
@ComponentScans({
    @ComponentScan(basePackages = "com.lisp.controller", includeFilters = @Filter(Controller.class)),
    @ComponentScan(basePackages = "com.lisp.service", includeFilters = @Filter(Service.class)),
    @ComponentScan(basePackages = "com.lisp.springframework.core.annotation")})
public class AnnotationApp {
    
    public static void main(String[] args) {
        try(AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();) {            
            ctx.register(AnnotationApp.class);
            ctx.refresh();
            MyServiceA myServiceA = ctx.getBean(MyServiceA.class);
            System.out.println(myServiceA);
            
            System.out.println(ctx.getBean(AnnotationApp.class));
        }
    }
}
